<html>
<head>
<style>
A
{

	text-decoration: none; color: 003265;
}

A:hover
{

	text-decoration: underline; color: 000000;
}


td, body, input
{

	font-family: Trebuchet MS, Arial; font-size: 11px;
}


.headerLinks
{

	color: white; font-weight: bold;
}

.headerLinks:hover
{

	color: #FFFFFF;
}

input, textarea
{
	border: 1px solid; border-color: #BBBBBB; background-color: #F0F0F0;
}

textarea
{
	font-size: 12px;
}
</style>
<SCRIPT LANGUAGE="JavaScript">
function ClipBoard( area )
{
	holdtext.innerText = area.innerText;
	Copied             = holdtext.createTextRange();

	if ( Copied.execCommand("Copy") == true )
	{
		alert('Text copied to clipboard successfully');
	}
}

function openAddNoteWindow ( funcID )
{
	var w   = 500, h = 500;
	var top = ( screen.height - h ) / 2 - 15, left = ( screen.width - w ) / 2;

	if ( top < 0 )
	{
		top = 0;
	}

	if ( left < 0 )
	{
		left = 0;
	}

	window.open('index.php?a=addnote&f=' + funcID,
		    'AddNote',
		    'width=' + w + ',height=' + h + ',top=' + top + ', left=' + left + ',scrollbars=yes');
}
</SCRIPT>
<title>txtSQL Documentation Functions : createtable</title>
</head>
<body bgcolor="FFFFFF" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0">

<table width="100%" cellspacing="0" cellpadding="3"
	<tr bgcolor="003265">
		<td><font color="white"><b>createtable</b></font></td>
		<td align="right">
			<a href="javascript:history.back()" class="headerLinks">Back</a>
			<font color="white"> | <a href="javascript:history.forward()" class="headerLinks">Forward</a> |
			<a href="index.html" class="headerLinks">Home</a>
		</td>
	</tr>
	<tr>
		<td height="8" background="shadow.gif" colspan="2">
		</td>
	</tr>
</table>
<br />

<table width="95%" cellspacing="1" cellpadding="3" align="center">
	<tr valign="top">
		<td width="125" style="border:1px solid; border-color: #BBBBBB" bgcolor="#FAFAFA">
			<a href="1.html">'Language Reference'</a><br />
			<br />

			<a href="13.html">User Functions</a><br />
			<br />

			<a href="19.html">Database Functions</a><br />
			<br />

			<a href="28.html">Data Manipulation Functions</a><br />
			<br />

			<b><a href="34.html">Table Functions</a></b><br />
			<li><a href="35.html">showtables</a></li><br />
			<li><b>createtable</b></li><br />
			<li><a href="37.html">droptable</a></li><br />
			<li><a href="38.html">altertable</a></li><br />
			<li><a href="39.html">describe</a></li><br />
			<li><a href="40.html">table_count</a></li><br />
			<li><a href="41.html">empty_cache</a></li><br />
			<li><a href="49.html">table_exists</a></li><br />
			<li><a href="51.html">last_insert_id</a></li><br />
			<br />

			<a href="42.html">Error Handling Functions</a><br />

		<br />		</td>
		<td style="padding-left: 35px;">
			<table width="100%">
				<tr valign="bottom">
					<td align="left" width="33%"><< <a href="35.html">Last Section ( showtables )</a></td>
					<td align="center" width="33%"><font size="6">createtable</font></td>
					<td align="right" width="33%"><a href="37.html">Next Section ( droptable )</a> >></td>
				</tr>
			</table>

			<table width="100%" cellpadding="3" cellspacing="0" border="0" style="border:1px solid;border-color:#BBBBBB;">
				<tr bgcolor="#F4F4F4" align="left">
					<td width="75"><b>Usage</b></td>
					<td><i>void</i> createtable ( array ('table' => $tablename, 'columns' => $columns [, 'db' => $db]) )</td>
				</tr>
				<tr bgcolor="#F4F4F4" align="left">
					<td width="75"><b>Purpose</b></td>
					<td>To create a txtSQL table inside a database</td>
				</tr>
				<tr bgcolor="#F4F4F4" align="left">
					<td width="75"><b>Availability</b></td>
					<td>txtSQL >= 2.2.2 RC2</td>
				</tr>
			</table>
			<BR />

			This function will create a txtSQL table with the name <i>$tablename</i>, as long as it does not already exist. The columns that will be in this table will be defined in <i>$columns</i> part of the array. <i>$columns</i> must be an array in the following format<br /><br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>array([$columnName => array([$coltype => $value]...)]... )</i>
			<br /><br />
			For more information on on column types, see the <i><a href="5.html">column types</a></i> section<br /><br />
			
			<b>Important</b>- To achieve the same results as this function before txtSQL 2.2.2 RC2, use the <i><a href="33.html">execute()</a></i> function<br />
			<b>Note</b>- If <i>$tablename</i> already exists, txtSQL will issue an error<br />
			<b>Note</b>- If no <i>$db</i> is specified and no database is already selected, txtSQL will issue an error
			<br /><br/>


			<table width="100%" cellspacing="1" cellpadding="3">
				<tr>
					<td align="left"><b>Example 21: createtable()</b>
					<td align="right"><a href="javascript: ClipBoard(copytext1)">Copy to Clipboard</a></td>
				</tr>
				<tr>
					<td colspan="2" bgcolor="#F4F4F4" style="border: 1px solid; border-color: #BBBBBB" id="copytext1">
						<code><font color="#000000">
						<font color="#0000BB">&lt;?php <br />$columns </font><font color="#007700">= array(</font><font color="#DD0000">'id'&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt; array(</font><font color="#DD0000">'type' </font><font color="#007700">=&gt; </font><font color="#DD0000">'int'</font><font color="#007700">, </font><font color="#DD0000">'auto_increment' </font><font color="#007700">=&gt; </font><font color="#0000BB">1</font><font color="#007700">, </font><font color="#DD0000">'permanent' </font><font color="#007700">=&gt; </font><font color="#0000BB">1 <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'name'&nbsp;&nbsp;</font><font color="#007700">=&gt; array(</font><font color="#DD0000">'type' </font><font color="#007700">=&gt; </font><font color="#DD0000">'string'</font><font color="#007700">, </font><font color="#DD0000">'max' </font><font color="#007700">=&gt; </font><font color="#0000BB">50</font><font color="#007700">), <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'email' </font><font color="#007700">=&gt; array(</font><font color="#DD0000">'type' </font><font color="#007700">=&gt; </font><font color="#DD0000">'string'</font><font color="#007700">, </font><font color="#DD0000">'max' </font><font color="#007700">=&gt; </font><font color="#0000BB">50</font><font color="#007700">) <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;); <br /><br /></font><font color="#0000BB">$sql</font><font color="#007700">-&gt;</font><font color="#0000BB">createtable</font><font color="#007700">(</font><font color="#DD0000">'db'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt; </font><font color="#DD0000">'testDb'</font><font color="#007700">, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'table'&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt; </font><font color="#DD0000">'testTable'</font><font color="#007700">, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'columns' </font><font color="#007700">=&gt; </font><font color="#0000BB">$columns</font><font color="#007700">); <br /></font><font color="#0000BB">?&gt;</font>
						</font>
						</code>
					</td>
				</tr>
			</table>
			<br />


			<TEXTAREA ID="holdtext" STYLE="display:none;"></TEXTAREA>

			<table width="100%" cellspacing="1" cellpadding="3" border="0" bgcolor="D0D0D0" align="center">
				<tr>
					<td><font size="1">User-Contributed Comments for: </font><br><b>createtable()</b></td>
					<td align="right" valign="top"><a href="javascript: openAddNoteWindow('36');"> <font size="1" style="text-decoration:underline;"></font></a></td>
				</tr>
				<tr>
					<td colspan="2" align="center" bgcolor="#EBEBEB"><font face="courier new" size="2">No comments found; </font></td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<br />

</body>
</html>